﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ex1.OverrideStandartOperators
{
    public enum StudentSpeciality
    {
        ComputerScience,
        SoftwareEngineering
    }
    public enum StudentUniversity
    {
        SofiaUniversity,
        TechnicalUniversity
    }
    public enum StudentFaculty
    {
        FMI,
        FKSU
    }

    class Student : ICloneable,IComparable<Student> 
    {
        public string FirstName { get; set; }
        public string MiddleName { get; set; }
        public string LastName { get; set; }
        public long SSN { get; set; }
        public string Adress { get; set; }
        public string PhoneNumber { get; set; }
        public string Email { get; set; }
        public string Course { get; set; }
        public StudentSpeciality Speciality { get; set; }
        public StudentUniversity University { get; set; }
        public StudentFaculty Faculty { get; set; }

        public Student(string fName, string mName, string lName, long SSN, string adress, string phoneNumber, string email,
            string course, StudentSpeciality speciality, StudentUniversity university, StudentFaculty faculty)
        {
            this.FirstName = fName;
            this.MiddleName = mName;
            this.LastName = lName;
            this.SSN = SSN;
            this.Adress = adress;
            this.PhoneNumber = phoneNumber;
            this.Email = email;
            this.Course = course;
            this.Speciality = speciality;
            this.University = university;
            this.Faculty = faculty;
        }

        public override string ToString()
        {
            StringBuilder outputInformation = new StringBuilder();
            outputInformation.Append("Student Information\n");
            outputInformation.Append
                (string.Format("Name: {0,-10}{1,-10}{2,-10}\n",this.FirstName,this.MiddleName,this.LastName));
            outputInformation.Append(string.Format("University: {0}\n", this.University));
            outputInformation.Append(string.Format("Speciality: {0}\n", this.Speciality));
            outputInformation.Append(string.Format("Faculty: {0}\n", this.Faculty));
            outputInformation.Append(string.Format("Course: {0}\n", this.Course));
            outputInformation.Append(string.Format("Email: {0}\n", this.Email));
            outputInformation.Append(string.Format("Phone Number: {0}\n", this.PhoneNumber));
            outputInformation.Append(string.Format("Adress: {0}\n", this.Adress));
            outputInformation.Append(string.Format("SSN: {0}\n", this.SSN));

            return outputInformation.ToString();
        }

        public override bool Equals(object obj)
        {
            if (obj == null || GetType() != obj.GetType()) return false;

            Student student = (Student)obj;

            if (this.FirstName == student.FirstName && this.MiddleName == student.MiddleName && this.LastName == student.LastName
                && this.SSN == student.SSN && this.Adress == student.Adress) return true;
            else return false;
        }

        public override int GetHashCode()
        {
            return (int)this.Adress.GetHashCode() ^ this.Course.GetHashCode() ^ 
                this.Email.GetHashCode() ^ this.SSN.GetHashCode();
        }

        public static bool operator == (Student student1, Student student2)
        {
            return Student.Equals(student1, student2);
        }

        public static bool operator !=(Student student1, Student student2)
        {
            return !(Student.Equals(student1, student2));
        }

        object ICloneable.Clone() 
        {
            return this.Clone();
        }

        private Student Clone()
        {
            Student original = this;
            Student copyStudent = new Student(original.FirstName, original.MiddleName, original.LastName, original.SSN,
                original.Adress, original.PhoneNumber, original.Email, original.Course, original.Speciality, original.University,
                original.Faculty);
            return copyStudent;
        }

        public int CompareTo(Student other)
        {
            int result = this.FirstName.CompareTo(other.FirstName);
            if (result != 0) return result;
            
            result = this.MiddleName.CompareTo(other.MiddleName);
            if (result != 0) return result;

            result = this.LastName.CompareTo(other.LastName);
            if (result != 0) return result;

            result = this.SSN.CompareTo(other.SSN);
            if (result != 0) return result;

            else return result;
        }
    }

    class OverrideStandartOperators
    {
        static void Main(string[] args)
        {
            Student myStudent = new Student("Pesho", "Goshov", "Petrov", 654312651265, "Lev Tolstoi 30", "0896405065",
                "krycipower@gmail.com", "2", StudentSpeciality.SoftwareEngineering, StudentUniversity.SofiaUniversity,
                StudentFaculty.FMI);

            Student myStudent2 = new Student("Pesho", "Goshov", "Petrov", 654312651265, "Lev Tolstoi 30", "0896405065",
                "krycipower@gmail.com", "2", StudentSpeciality.SoftwareEngineering, StudentUniversity.SofiaUniversity,
                StudentFaculty.FMI);

            Console.WriteLine(myStudent);
            Console.WriteLine(myStudent.CompareTo(myStudent2));
        }
    }
}
